<%@ page import="cn.gpnu.domain.Text" %><%--
  Created by IntelliJ IDEA.
  User: LOG
  Date: 2020/12/6
  Time: 11:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>日志本</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <style>
        body{
            background-size: 100% 100%;
            position: absolute;
            padding: 0;
            margin: 0;
            background:url("img/日志背景.jpg") no-repeat;
            height: 100px;
            width: 100%;
            background-size: 100%;
            font-style: initial;
        }
        .p_1{
            font-size: 200%;
            text-align: center;
            color: seashell;
        }
        .p_2{
            font-size: 150%;
            text-align: center;
            color: salmon;
            margin-left: 129px;
        }

        .p_3{
            margin-right: 16px;
        }
        .form_1{
            background: white;
            width: 1000px;
            height: 580px;
            border: #5bc0de solid 5px;
            text-align: center;
        }
        .div_form{

            margin-left: 273px;
        }
        .title{
            width: 160px;
            height: 40px;
            border-radius: 7px;
            border: #5bc0de solid 2px;
        }
        .textarea{
            width: 900px;
            height: 500px;
            border: mediumpurple solid 2px;
        }
        .Save{
            float: right;
            margin-bottom: 150px;
            margin-right: 50px;
            height: 50px;
        }
        .return{
            float: left;
            margin-bottom: 150px;
            margin-left: 50px;
            height: 50px;
        }
        .bottom{
            text-align: center;
            margin-left: 127.5px;
            height: 50px;
        }
        .Content_p{
            float: left;
            margin-left: 10px;
        }
        .p_title{
            margin-right: 20px;
            color: #5bc0de;
            font-size: 150%;
        }
    </style>
</head>
<body>

<div>
    <div>
        <h2 class="p_1">Daily Text</h2>
    </div>
    <div class="div_form">
        <form class="form_1" action="">
            <br>
            <p class="p_3">
                <span class="p_title">Title</span><input id = "title" class="title" type="text" name="fname" />
            </p>
            <p class="Content_p">
                Content
            </p>
            <p id = "Content"></p>
                <textarea id = "textarea" class="textarea" name="txt" clos=",50" rows="5" warp="virtual"></textarea>
        </form>
    </div>
    <div class="Save">
        <button id = "button_01" type="button" class="btn btn-info btn-lg">保存日志</button>
    </div>
    <div class="return">
        <button id = "button_02" type="button" class="btn btn-info btn-lg">返回森林</button>
    </div>
    <div class="bottom div_2">
        <p class="p_2">Click The Save to log</p>
    </div>
</div>

<%
    Text text = (Text)request.getAttribute("text");
    System.out.println(text.getTitle());
%>
<input type="hidden" id="get_title" value="<%=text.getTitle()%>"/>
<input type="hidden" id="get_text" value="<%=text.getText()%>"/>

<script>
    // var title = $("title");
    var get_title = document.getElementById("get_title");
    var title = document.getElementById("title");
    title.value = get_title.value;

    var textarea = document.getElementById("textarea");
    var get_text = document.getElementById("get_text");
    textarea.value = get_text.value;
    // var textarea = document.getElementById("textarea").value;

    // var textarea = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '); //转换格式

    // var btn_01 = document.getElementById("button_01");
    // btn_01.onclick  = function(){
    //     $.ajax({
    //         url:"SaveText",
    //         type:"GET",
    //         data:{"textarea":textarea,"title":title},
    //         success:function (data) {
    //             alert("保存成功")
    //         },error:function () {
    //             alert("保存失败");
    //         }
    //     })
    // }
    var btn_01 = document.getElementById("button_01");
    btn_01.onclick  = function(){
        title = document.getElementById("title").value;
        textarea1 = document.getElementById("textarea").value;
        var textarea2 = textarea1.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');  //转换格式
        $.ajax({
                    url:"SaveText",
                    type:"GET",
                    data:{"textarea":textarea1,"title":title},
                    success:function (data) {
                        alert("保存成功");
                    },error:function () {
                        alert("保存失败");
                    }
                })
         }

    // var btn_02 = document.getElementById("button_02");
    // btn_02.onclick  = function(){
    //     get_title = document.getElementById("get_title").value;
    //     title.value = get_title;
    // }

    // $(document).ready(function(){
    //     $.ajax({
    //     url:"TakeText",
    //     type:"GET",
    //     data:{"user_id":1},
    //     success:function (text) {
    //         // alert(text.getID());
    //         get_title = document.getElementById("get_title").value;
    //         title.value = get_title;
    //     },error:function () {
    //         alert("读取失败");
    //     }
    // })
    // });

    // function TakeIt() {
    //     $.ajax({
    //         url:"TakeText",
    //         type:"GET",
    //         data:{"user_id":1},
    //         success:function (text) {
    //             // alert(text.getID());
    //              get_title = document.getElementById("get_title").value;
    //              title.value = get_title;
    //         },error:function () {
    //             alert("读取失败");
    //         }
    //     })
    // }
     // function init() {
     //     var text = $("div.text").text(); //先取出未转换格式前端数据
     //     var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');  //转换格式
     //     $("div.text").empty();
     //     $("div.text").append(des);
     // }
</script>

</body>
</html>
